package com.happycat.service.impl;
 
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.happycat.Pagination;
import com.happycat.ResponseHeaderModel;
import com.happycat.ResponseModel;
import com.happycat.SysContants;
import com.happycat.mapper.UserActiveMessagingMapper;
import com.happycat.mobile.model.UserActiveMessaging;
import com.happycat.mobile.service.GenerateIdService;
import com.happycat.mobile.service.UserActiveMessagingService;
import com.happycat.utils.ResponseModelUtils;
/**
 * Module: UserActiveMessaging.java
 * 
 * @author liaoyong
 * @since JDK 1.8
 * @version 1.0
 * @date 2020-08-01
 * @Descriptions:
 */
@Service
public class UserActiveMessagingServiceImpl extends ServiceImpl<UserActiveMessagingMapper, UserActiveMessaging> implements UserActiveMessagingService {
 	
	@Autowired
	private GenerateIdService generateIdService;
	
 	public ResponseModel<UserActiveMessaging> selectOne(UserActiveMessaging userActiveMessaging){
		
 		
 		return ResponseModelUtils.success("查询成功", this.baseMapper.queryDetail(userActiveMessaging));
 	
 	}
	
	public ResponseHeaderModel	add(UserActiveMessaging userActiveMessaging){
		ResponseHeaderModel responseHeaderModel = new ResponseHeaderModel();
		userActiveMessaging.setId(generateIdService.nextDefaultSerialNumber());
		userActiveMessaging.setSendTime(new Date());
		boolean result = save(userActiveMessaging);
		if(result) {
			responseHeaderModel.setCode(SysContants.SYS_SUCCESS_CODE);
			responseHeaderModel.setMessage("新增成功");
		}else {
			responseHeaderModel.setCode(SysContants.SYS_FAIL_CODE);
			responseHeaderModel.setMessage("新增失败");
		}
		return responseHeaderModel;
	}
	
	public ResponseHeaderModel	modify(UserActiveMessaging userActiveMessaging){
			ResponseHeaderModel responseHeaderModel = new ResponseHeaderModel();
		
		boolean result = updateById(userActiveMessaging);
		if(result) {
			responseHeaderModel.setCode(SysContants.SYS_SUCCESS_CODE);
			responseHeaderModel.setMessage("修改成功");
		}else {
			responseHeaderModel.setCode(SysContants.SYS_FAIL_CODE);
			responseHeaderModel.setMessage("修改失败");
		}
		return responseHeaderModel;
	}
	
	public ResponseModel<Page<UserActiveMessaging>> pageList(Pagination<UserActiveMessaging>page){
		ResponseModel<Page<UserActiveMessaging>> responseModel = new ResponseModel<>();
		responseModel.setCode(SysContants.SYS_SUCCESS_CODE);
		responseModel.setMessage("查询成功");
		responseModel.setData(this.baseMapper.pageList(page,new QueryWrapper<UserActiveMessaging>(page.getEntity())));
		return responseModel;
	}

	@Override
	public ResponseHeaderModel cancleLike(UserActiveMessaging userActiveMessaging) {
		QueryWrapper<UserActiveMessaging> queryWrapper = new QueryWrapper<UserActiveMessaging>(userActiveMessaging);
		remove(queryWrapper);
		return ResponseModelUtils.success("取消点赞成功", null);
	}

}
